﻿<?php
include_once('common/header.php');	
if($AppUI->id <= 0 || !isset($_SERVER['HTTP_REFERER'])) {
	$this->_redirect(HOST_VFRIEND);
}
$strRefer	= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$intAlbumId	= $objRequest->getParam('palbumid',0);
$intPerm	= $objRequest->getParam('pperm',0);
$strName	= $objRequest->getParam('pname','');
$oFile		= $_FILES['pimage'];
$intError	= 0;
if($intAblumId <= -1) {
	if($strName == '') $intError = 8;
	elseif($strName != '' && strlen($strName) < 5) $intError = 9;
}elseif($intAlbumId == 0) $intError = 10;
if(isset($oFile) && $oFile) {
	$strImage	= '';
	$arrImg 	= Globals::uploadAlbum($oFile,$strImage);
	if($arrImg['error'] == 0) {	
		if(isset($_SESSION['ipost'])) unset($_SESSION['ipost']);
		$objPhoto 	= new Photo();
		$intImageId	= 0;
		$intError	= $objPhoto->addForAlbum($AppUI->id,$intAlbumId,$strName,$intPerm,$strImage,$intImageId);
		if($intError == 0) {
			$_SESSION['poimage'][] = $intImageId;
			Vfriend_Function::setMsg($arrMessage[4]);
		} else {
			$intError = 13;
		}
	}
	else {
		$intError = 12;
	}
} else {
	$intError	= 11;
}
if($intError > 0) {
	$_SESSION['ipost']	= $this->getParams();
	Vfriend_Function::setError($arrError[$intError]);
}
$strRefer	= $strRefer ? $strRefer : Vfriend_Function::linkFullhouseForPhoto($AppUI->username,$AppUI->hex);
Vfriend_Function::redirect($strRefer);
exit();
?>